<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
    <META http-equiv=Content-Type content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="/sys/resources/css/reset.css" type="text/css" media="screen"/>
    <link rel="stylesheet" href="/sys/resources/css/style.css" type="text/css" media="screen"/>
    <link rel="stylesheet" href="/sys/resources/css/invalid.css" type="text/css" media="screen"/>
    <link rel="stylesheet" href="/sys/resources/css/bootstrap.css" type="text/css" media="screen"/>
    <link rel="stylesheet" href="/sys/resources/css/bootstrap-datetimepicker.min.css" type="text/css" media="screen"/>

    <script type="text/javascript" src="/sys/resources/scripts/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="/sys/resources/scripts/zhTable.js"></script>
    <script type="text/javascript" src="/sys/resources/scripts/bootstrap.js"></script>
    <script type="text/javascript" src="/sys/resources/scripts/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="/sys/resources/scripts/bootstrap-datetimepicker.zh-CN.js"></script>


    <script type="text/javascript" src="/sys/resources/scripts/simpla.jquery.configuration.js"></script>
    <script type="text/javascript" src="/sys/resources/scripts/facebox.js"></script>

    <title>管理</title>
    <style type="text/css">
        table td{
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            max-width: 100px
        }
    </style>
    <script >
        var moduleName="document";
        var deleteUrl = "/sys/"+moduleName+"/delete.do";
        function initData(tds,data,index)
        {
            $(tds[0]).html("<input type='checkbox' value='"+data.id+"'>");
            $(tds[1]).html(data.title);
            switch (data.type){
                case "1":
                    $(tds[2]).html("基础知识");
                    break;
                case "2":
                    $(tds[2]).html("入党必读");
                    break;
                case "3":
                    $(tds[2]).html("党史文献");
                    break;
            }
            $(tds[3]).html(data.author);

            $(tds[4]).html(data.time);
            var oper = "<a role='button' class='bottom btn-primary btn-sm' href='/sys/"+moduleName+"/edit.do?id="+data.id+"'>编辑</a>"
            $(tds[5]).html(oper);
        }
        var zhTable = null;
        $(function () {
            //初始化table的js，
            //$("#tablePageDiv") 指定操作div ，
            //initData 填充数据的方法
            //true 页面初始化时加载数据
            zhTable = new initZhTable($("#tablePageDiv"), initData,true);


            //初始化时间插件
            $('.form_datetime').datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'zh-CN',
                weekStart: 1,
                todayBtn: 1,
                autoclose: 1,
                todayHighlight: 1,
                startView: 2,
                minView: 2,
                forceParse: 0
            }).click(function () {
                        $(this).val("");
                    });
        });

        function deleteDate() {
            var ids = zhTable.getAllChecked();
            if(ids == null || ids == "")
            {
                alert("请选择数据");
                return;
            }
            if (!window.confirm("危险操作，你确定删除吗？"))   //确定是否删除
                return false;

            var query = new Object();
            query.id = ids;

            //发起请求 提交数据
            $.ajax({
                url: deleteUrl,
                type:"POST",
                cache: false,
                data:{ids:ids},
                dataType:"json",
                success: function(data) {
                    if (data.num == '-1') {
                        alert("删除异常！");
                    }
                    else {
                        alert("成功，删除" + data.num + "个！")
                        $(".searchBtn").click();//重新加载
                    }
                },
                error : function() {
                    alert("请求异常");
                }
            });
        }
    </script>

</HEAD>
<BODY class="mian_bg">
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
    <TR height=28>
        <TD class="addr_td">&nbsp;&nbsp;<img src="/sys/resources/images/addr_icon.png">&nbsp;当前位置: 资料管理>资料管理</TD>
    </TR>
    <TR>
        <TD bgColor=#7ca600 height=1></TD>
    </TR>
    <TR>
        <TD bgColor=#8ebe00 height=1></TD>
    </TR>
</TABLE>

<div class="container">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">资料列表</h3>
        </div>
        <div class="panel-body">
            <div id="tablePageDiv">
                <div id="searchDiv">
                    <form name="searchDivForm" url="/sys/document/query.do">
                        <div class="row">
                            <div class="col-xs-4">
                                <div class="input-group">
                                    <span class="input-group-addon">资料名称</span>
                                    <input type="text" name="title" id="title" value="" class="form-control">
                                </div>
                            </div>

                            <div class="col-xs-4">
                                <div class="input-group">
                                    <span class="input-group-addon">资料类型</span>
                                    <select class="form-control" name="type">
                                        <option value="" selected></option>
                                        <option value="1" >基础知识</option>
                                        <option value="2" >入党必读</option>
                                        <option value="3" >党史文献</option>
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="row" style="margin-top: 7px;">
                            <div class="col-xs-1">
                                <button type="button" class="btn btn-success btn-block searchBtn">查询</button>
                            </div>
                            <div class="col-xs-1">
                                <a href="/sys/document/add.do" class="btn btn-success btn-block">增加</a>
                            </div>
                            <div class="col-xs-1">
                                <button type="button" onclick="deleteDate();" class="btn btn-success btn-block">删除</button>
                            </div>

                        </div>
                    </form>
                </div>

                <div id="tableDiv" style="margin-top: 10px;">
                    <table class="table table-hover table-bordered .table-condensed">
                        <thead>
                        <tr  class="bg-success">
                            <th style="width: 60px;"><input class="checkAll" type="checkbox"/>全选</th>
                            <th>资料名称</th>
                            <th>类型</th>
                            <th>作者姓名</th>
                            <th>创建时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>

                        </tbody>
                    </table>
                    <ul class="pagination">

                    </ul>
                </div>
            </div>
        </div>
    </div>
</div>
</BODY>
</HTML>